CM3D2 Converter.misc_RENDER_PT_render
1# 「プロパティ」エリア → 「レンダー」タブ → 「レンダー」パネル 2import os 3import re 4import sys 5import math 6import bpy 7import time 8import bmesh 9import mathutils 10from . import common 11from . import compat 12 13 14# メニュー等に項目追加 15def menu_func(self, context): 16 self.layout.operator(CNV_OT_render_cm3d2_icon.bl_idname, icon_value=common.kiss_icon()) 17 18 19@compat.BlRegister() 20class CNV_OT_render_cm3d2_icon(bpy.types.Operator): 21 bl_idname = 'render.render_cm3d2_icon' 22 bl_label = "CM3D2メニュー用のアイコンをレンダリング" 23 bl_description = "CM3D2内のアイコン画像に使用できそうな画像をレンダリングします" 24 bl_options = {'REGISTER', 'UNDO'} 25 26 items = [ 27 ('FACE_TEXTURE', "面のテクスチャで", "", 'FACESEL_HLT', 1), 28 ('NOW_MATERIAL', "今のマテリアルで", "", 'MATERIAL', 2), 29 ] 30 mode = bpy.props.EnumProperty(items=items, name="モード", default='FACE_TEXTURE') 31 32 use_freestyle = bpy.props.BoolProperty(name="輪郭線を描画", default=True) 33 line_thickness = bpy.props.FloatProperty(name="線の太さ", default=0.2, min=0, max=0.5, soft_min=0, soft_max=0.5, step=10, precision=2, subtype='PIXEL') 34 line_color = bpy.props.FloatVectorProperty(name="線の色", default=(0, 0, 0), min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2, subtype='COLOR', size=3) 35 36 resolution = bpy.props.IntProperty(name="解像度", default=80, min=10, max=800, soft_min=10, soft_max=800, subtype='PIXEL') 37 camera_angle = bpy.props.FloatVectorProperty(name="カメラ角度", default=(0.576667, 0.576667, 0.578715), min=-10, max=10, soft_min=-10, soft_max=10, step=1, precision=2, subtype='DIRECTION', size=3) 38 camera_move = bpy.props.FloatVectorProperty(name="カメラ移動", default=(0, 0), min=-10, max=10, soft_min=-10, soft_max=10, step=10, precision=2, subtype='XYZ', size=2) 39 zoom_multi = bpy.props.IntProperty(name="ズーム倍率", default=100, min=10, max=190, soft_min=10, soft_max=190, step=10, subtype='PERCENTAGE') 40 41 use_background_color = bpy.props.BoolProperty(name="背景を使用", default=True) 42 background_color = bpy.props.FloatVectorProperty(name="背景色", default=(1, 1, 1), min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2, subtype='COLOR', size=3) 43 is_round_background = bpy.props.BoolProperty(name="隅を丸める", default=True) 44 45 layer_image = bpy.props.StringProperty(name="重ねる画像", default="") 46 47 @classmethod 48 def poll(cls, context): 49 obs = context.selected_objects 50 if len(obs): 51 for ob in obs: 52 if ob.type == 'MESH': 53 return True 54 return False 55 56 def invoke(self, context, event): 57 obs = context.selected_objects 58 for ob in obs: 59 if ob.type != 'MESH': 60 continue 61 me = ob.data 62 uv = compat.get_active_uv(me) 63 if uv and uv.data[0]: 64 self.mode = 'FACE_TEXTURE' 65 break 66 else: 67 self.mode = 'NOW_MATERIAL' 68 69 if 'render_cm3d2_icon_background_color' in context.scene: 70 try: 71 color = str(context.scene['render_cm3d2_icon_background_color']).split(",") 72 if len(color) == 3: 73 self.background_color[0] = float(color[0]) 74 self.background_color[1] = float(color[1]) 75 self.background_color[2] = float(color[2]) 76 except: 77 pass 78 if 'render_cm3d2_icon_background_color_layer_image' in context.scene: 79 self.layer_image = context.scene['render_cm3d2_icon_background_color_layer_image'] 80 81 return context.window_manager.invoke_props_dialog(self) 82 83 def draw(self, context): 84 self.layout.prop(self, 'resolution', icon=compat.icon('FILE_IMAGE'), slider=True) 85 col = self.layout.column(align=True) 86 col.label(text="テクスチャ参照方法", icon=compat.icon('SHADING_TEXTURE')) 87 row = col.row() 88 row.prop(self, 'mode', icon=compat.icon('SHADING_TEXTURE'), expand=True) 89 self.layout.separator() 90 91 row = compat.layout_split(self.layout, factor=1 / 3, align=True) 92 row.prop(self, 'use_freestyle', icon='LINE_DATA', text="輪郭線") 93 row.prop(self, 'line_thickness', icon='ARROW_LEFTRIGHT', slider=True, text="") 94 row.prop(self, 'line_color', icon='COLOR', text="") 95 self.layout.separator() 96 97 col = self.layout.column(align=True) 98 col.label(text="カメラ角度", icon='FILE_REFRESH') 99 col.prop(self, 'camera_angle', text="") 100 self.layout.prop(self, 'camera_move', icon='ARROW_LEFTRIGHT') 101 self.layout.prop(self, 'zoom_multi', icon='VIEWZOOM', slider=True) 102 self.layout.separator() 103 104 row = compat.layout_split(self.layout, factor=0.333333333, align=True) 105 row.prop(self, 'use_background_color', icon='WORLD') 106 row.prop(self, 'background_color', icon='COLOR', text="") 107 row.prop(self, 'is_round_background', icon=compat.icon('CLIPUV_DEHLT')) 108 109 self.layout.separator() 110 self.layout.prop_search(self, 'layer_image', context.blend_data, "images", icon='MOD_UVPROJECT') 111 112 def execute(self, context): 113 c = self.background_color[:] 114 context.scene['render_cm3d2_icon_background_color'] = ",".join([str(c[0]), str(c[1]), str(c[2])]) 115 context.scene['render_cm3d2_icon_background_color_layer_image'] = self.layer_image 116 117 override = context.copy() 118 obs = context.selected_objects 119 120 material_restores, pre_mate_settings = None, None 121 if self.mode == 'FACE_TEXTURE': 122 material_restores = [] 123 temp_mates = [] 124 for ob in obs: 125 material_restores.append(common.material_restore(ob)) 126 override['object'] = ob 127 bpy.ops.object.material_slot_add(override) 128 if len(ob.material_slots) > 0: 129 temp_mate = context.blend_data.materials.new("temp") 130 ob.material_slots[0].material = temp_mate 131 if compat.IS_LEGACY: 132 temp_mate.use_shadeless = True 133 temp_mate.use_face_texture = True 134 temp_mate.use_transparency = True 135 temp_mate.alpha = 0.0 136 temp_mate.use_face_texture_alpha = True 137 temp_mates.append(temp_mate) 138 139 elif self.mode == 'NOW_MATERIAL': 140 if compat.IS_LEGACY: 141 pre_mate_settings = [] 142 for ob in obs: 143 setting = [] 144 for slot in ob.material_slots: 145 if not slot.material: 146 continue 147 mate = slot.material 148 setting.append([mate, mate.use_shadeless]) 149 mate.use_shadeless = True 150 pre_mate_settings.append(setting) 151 152 xs, ys, zs = [], [], [] 153 if compat.IS_LEGACY: 154 for ob in obs: 155 if ob.type == 'MESH': 156 temp_me = ob.to_mesh(context.scene, apply_modifiers=True, settings='PREVIEW') 157 for vert in temp_me.vertices: 158 co = ob.matrix_world * vert.co 159 xs.append(co.x) 160 ys.append(co.y) 161 zs.append(co.z) 162 common.remove_data(temp_me) 163 else: 164 depsgraph = context.evaluated_depsgraph_get() 165 for ob in obs: 166 if ob.type == 'MESH': 167 # depsgraphから取得されたob_eval: すべてのmodifierを考慮 168 ob_eval = ob.evaluated_get(depsgraph) 169 temp_me = ob_eval.to_mesh() 170 for vert in temp_me.vertices: 171 co = ob.matrix_world @ vert.co 172 xs.append(co.x) 173 ys.append(co.y) 174 zs.append(co.z) 175 ob_eval.to_mesh_clear() 176 177 center_co = mathutils.Vector((0, 0, 0)) 178 center_co.x = (min(xs) + max(xs)) / 2.0 179 center_co.y = (min(ys) + max(ys)) / 2.0 180 center_co.z = (min(zs) + max(zs)) / 2.0 181 182 hide_render_restore = common.hide_render_restore() 183 pre_scene_camera = context.scene.camera 184 temp_camera = context.blend_data.cameras.new("render_cm3d2_icon_temp") 185 temp_camera_ob = context.blend_data.objects.new("render_cm3d2_icon_temp", temp_camera) 186 try: 187 maxs = [-999, -999, -999] 188 mins = [999, 999, 999] 189 for ob in obs: 190 for i in range(8): 191 for j in range(3): 192 v = ob.bound_box[i][j] 193 if maxs[j] < v: 194 maxs[j] = v 195 if v < mins[j]: 196 mins[j] = v 197 198 lens = [maxs[0] - mins[0]] 199 lens.append(maxs[1] - mins[1]) 200 lens.append(maxs[2] - mins[2]) 201 lens.sort() 202 zoom = lens[-1] * 1.2 203 204 compat.link(context.scene, temp_camera_ob) 205 context.scene.camera = temp_camera_ob 206 temp_camera.type = 'ORTHO' 207 temp_camera.ortho_scale = zoom * (self.zoom_multi * 0.01) 208 209 direct = self.camera_angle.copy() 210 direct.rotate( mathutils.Euler((math.radians(90), 0, 0), 'XYZ') ) 211 temp_camera_ob.rotation_mode = 'QUATERNION' 212 temp_camera_ob.rotation_quaternion = direct.to_track_quat('Z', 'Y') 213 temp_camera_ob.location = direct * 10 214 temp_camera_ob.location += center_co 215 vec = mathutils.Vector() 216 vec.x, vec.y = -self.camera_move.x, -self.camera_move.y 217 temp_camera_ob.location += compat.mul(direct.to_track_quat('Z', 'Y'), vec) 218 219 context.scene.render.resolution_x = self.resolution 220 context.scene.render.resolution_y = self.resolution 221 context.scene.render.resolution_percentage = 100 222 223 context.scene.world.light_settings.use_ambient_occlusion = False 224 if compat.IS_LEGACY: 225 context.scene.world.light_settings.ao_blend_type = 'ADD' 226 context.scene.world.light_settings.gather_method = 'RAYTRACE' 227 context.scene.world.light_settings.samples = 10 228 229 context.scene.render.alpha_mode = 'SKY' if self.use_background_color else 'TRANSPARENT' 230 context.scene.world.horizon_color = self.background_color 231 else: 232 # TODO 代替処理 233 pass 234 235 if self.use_freestyle: 236 pre_use_freestyle = context.scene.render.use_freestyle 237 pre_line_thickness = context.scene.render.line_thickness 238 context.scene.render.use_freestyle = True 239 context.scene.render.line_thickness = self.line_thickness 240 if compat.IS_LEGACY: 241 context.scene.render.layers.active.freestyle_settings.crease_angle = 1.58825 242 temp_lineset = context.scene.render.layers.active.freestyle_settings.linesets.new("temp") 243 temp_lineset.linestyle.color = self.line_color 244 else: 245 # TODO view_layersのactive取得方法 246 layer = context.scene.view_layers[0] 247 layer.freestyle_settings.crease_angle = 1.58825 248 temp_lineset = layer.freestyle_settings.linesets.new("temp") 249 temp_lineset.linestyle.color = self.line_color 250 251 # コンポジットノード # 252 pre_use_nodes = context.scene.use_nodes 253 context.scene.use_nodes = True 254 node_tree = context.scene.node_tree 255 node_tree.nodes.clear() 256 257 in_node = node_tree.nodes.new('CompositorNodeRLayers') 258 in_node.location = (0, 0) 259 260 img_node = node_tree.nodes.new('CompositorNodeImage') 261 img_node.location = (0, -300) 262 if "Icon Alpha" in context.blend_data.images: 263 icon_alpha_img = context.blend_data.images["Icon Alpha"] 264 else: 265 blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend") 266 with context.blend_data.libraries.load(blend_path) as (data_from, data_to): 267 data_to.images = ["Icon Alpha"] 268 icon_alpha_img = data_to.images[0] 269 img_node.image = icon_alpha_img 270 271 scale_node = node_tree.nodes.new('CompositorNodeScale') 272 scale_node.location = (250, -300) 273 scale_node.space = 'RENDER_SIZE' 274 275 mix_node = node_tree.nodes.new('CompositorNodeMixRGB') 276 mix_node.location = (500, -100) 277 mix_node.blend_type = 'MULTIPLY' 278 279 alpha_node = node_tree.nodes.new('CompositorNodeSetAlpha') 280 alpha_node.location = (750, 0) 281 282 out_node = node_tree.nodes.new('CompositorNodeComposite') 283 out_node.location = (1500, 0) 284 285 layer_img = None 286 if self.layer_image in context.blend_data.images: 287 layer_img = context.blend_data.images[self.layer_image] 288 if layer_img: 289 layer_img_node = node_tree.nodes.new('CompositorNodeImage') 290 layer_img_node.location = (750, -200) 291 layer_img_node.image = layer_img 292 293 layer_scale_node = node_tree.nodes.new('CompositorNodeScale') 294 layer_scale_node.location = (1000, -200) 295 layer_scale_node.space = 'RENDER_SIZE' 296 297 layer_add_node = node_tree.nodes.new('CompositorNodeAlphaOver') 298 layer_add_node.location = (1250, 0) 299 300 node_tree.links.new(layer_add_node.inputs[1], alpha_node.outputs[0]) 301 node_tree.links.new(layer_scale_node.inputs[0], layer_img_node.outputs[0]) 302 node_tree.links.new(layer_add_node.inputs[2], layer_scale_node.outputs[0]) 303 node_tree.links.new(out_node.inputs[0], layer_add_node.outputs[0]) 304 else: 305 node_tree.links.new(out_node.inputs[0], alpha_node.outputs[0]) 306 307 node_tree.links.new(alpha_node.inputs[0], in_node.outputs[0]) 308 node_tree.links.new(mix_node.inputs[1], in_node.outputs[1]) 309 node_tree.links.new(scale_node.inputs[0], img_node.outputs[0]) 310 node_tree.links.new(mix_node.inputs[2], scale_node.outputs[0]) 311 if self.is_round_background: 312 node_tree.links.new(alpha_node.inputs[1], mix_node.outputs[0]) 313 # コンポジットノード # 314 315 bpy.ops.render.render() 316 317 node_tree.nodes.clear() 318 context.scene.use_nodes = False 319 common.remove_data([icon_alpha_img]) 320 321 if self.use_freestyle: 322 context.scene.render.use_freestyle = pre_use_freestyle 323 context.scene.render.line_thickness = pre_line_thickness 324 common.remove_data([temp_lineset.linestyle]) 325 if compat.IS_LEGACY: 326 context.scene.render.layers.active.freestyle_settings.linesets.remove(temp_lineset) 327 else: 328 layer = context.scene.view_layers[0] 329 layer.freestyle_settings.linesets.remove(temp_lineset) 330 331 img = context.blend_data.images["Render Result"] 332 tex_basename = common.remove_serial_number(context.active_object.name.split('.')[0]) 333 img['tex Name'] = tex_basename + "_i_.tex" 334 img['cm3d2_path'] = common.BASE_PATH_TEX + tex_basename + "_i_.png" 335 area = common.get_request_area(context, 'IMAGE_EDITOR') 336 common.set_area_space_attr(area, 'image', img) 337 338 finally: 339 common.remove_data([temp_camera_ob, temp_camera]) 340 context.scene.camera = pre_scene_camera 341 342 hide_render_restore.restore() 343 if material_restores: 344 for material_restore in material_restores: 345 material_restore.restore() 346 common.remove_data(temp_mates) 347 if pre_mate_settings: 348 for ob_mate in pre_mate_settings: 349 for mate, is_shadeless in ob_mate: 350 mate.use_shadeless = is_shadeless 351 352 return {'FINISHED'}
@compat.BlRegister()
class
CNV_OT_render_cm3d2_icon20@compat.BlRegister() 21class CNV_OT_render_cm3d2_icon(bpy.types.Operator): 22 bl_idname = 'render.render_cm3d2_icon' 23 bl_label = "CM3D2メニュー用のアイコンをレンダリング" 24 bl_description = "CM3D2内のアイコン画像に使用できそうな画像をレンダリングします" 25 bl_options = {'REGISTER', 'UNDO'} 26 27 items = [ 28 ('FACE_TEXTURE', "面のテクスチャで", "", 'FACESEL_HLT', 1), 29 ('NOW_MATERIAL', "今のマテリアルで", "", 'MATERIAL', 2), 30 ] 31 mode = bpy.props.EnumProperty(items=items, name="モード", default='FACE_TEXTURE') 32 33 use_freestyle = bpy.props.BoolProperty(name="輪郭線を描画", default=True) 34 line_thickness = bpy.props.FloatProperty(name="線の太さ", default=0.2, min=0, max=0.5, soft_min=0, soft_max=0.5, step=10, precision=2, subtype='PIXEL') 35 line_color = bpy.props.FloatVectorProperty(name="線の色", default=(0, 0, 0), min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2, subtype='COLOR', size=3) 36 37 resolution = bpy.props.IntProperty(name="解像度", default=80, min=10, max=800, soft_min=10, soft_max=800, subtype='PIXEL') 38 camera_angle = bpy.props.FloatVectorProperty(name="カメラ角度", default=(0.576667, 0.576667, 0.578715), min=-10, max=10, soft_min=-10, soft_max=10, step=1, precision=2, subtype='DIRECTION', size=3) 39 camera_move = bpy.props.FloatVectorProperty(name="カメラ移動", default=(0, 0), min=-10, max=10, soft_min=-10, soft_max=10, step=10, precision=2, subtype='XYZ', size=2) 40 zoom_multi = bpy.props.IntProperty(name="ズーム倍率", default=100, min=10, max=190, soft_min=10, soft_max=190, step=10, subtype='PERCENTAGE') 41 42 use_background_color = bpy.props.BoolProperty(name="背景を使用", default=True) 43 background_color = bpy.props.FloatVectorProperty(name="背景色", default=(1, 1, 1), min=0, max=1, soft_min=0, soft_max=1, step=10, precision=2, subtype='COLOR', size=3) 44 is_round_background = bpy.props.BoolProperty(name="隅を丸める", default=True) 45 46 layer_image = bpy.props.StringProperty(name="重ねる画像", default="") 47 48 @classmethod 49 def poll(cls, context): 50 obs = context.selected_objects 51 if len(obs): 52 for ob in obs: 53 if ob.type == 'MESH': 54 return True 55 return False 56 57 def invoke(self, context, event): 58 obs = context.selected_objects 59 for ob in obs: 60 if ob.type != 'MESH': 61 continue 62 me = ob.data 63 uv = compat.get_active_uv(me) 64 if uv and uv.data[0]: 65 self.mode = 'FACE_TEXTURE' 66 break 67 else: 68 self.mode = 'NOW_MATERIAL' 69 70 if 'render_cm3d2_icon_background_color' in context.scene: 71 try: 72 color = str(context.scene['render_cm3d2_icon_background_color']).split(",") 73 if len(color) == 3: 74 self.background_color[0] = float(color[0]) 75 self.background_color[1] = float(color[1]) 76 self.background_color[2] = float(color[2]) 77 except: 78 pass 79 if 'render_cm3d2_icon_background_color_layer_image' in context.scene: 80 self.layer_image = context.scene['render_cm3d2_icon_background_color_layer_image'] 81 82 return context.window_manager.invoke_props_dialog(self) 83 84 def draw(self, context): 85 self.layout.prop(self, 'resolution', icon=compat.icon('FILE_IMAGE'), slider=True) 86 col = self.layout.column(align=True) 87 col.label(text="テクスチャ参照方法", icon=compat.icon('SHADING_TEXTURE')) 88 row = col.row() 89 row.prop(self, 'mode', icon=compat.icon('SHADING_TEXTURE'), expand=True) 90 self.layout.separator() 91 92 row = compat.layout_split(self.layout, factor=1 / 3, align=True) 93 row.prop(self, 'use_freestyle', icon='LINE_DATA', text="輪郭線") 94 row.prop(self, 'line_thickness', icon='ARROW_LEFTRIGHT', slider=True, text="") 95 row.prop(self, 'line_color', icon='COLOR', text="") 96 self.layout.separator() 97 98 col = self.layout.column(align=True) 99 col.label(text="カメラ角度", icon='FILE_REFRESH') 100 col.prop(self, 'camera_angle', text="") 101 self.layout.prop(self, 'camera_move', icon='ARROW_LEFTRIGHT') 102 self.layout.prop(self, 'zoom_multi', icon='VIEWZOOM', slider=True) 103 self.layout.separator() 104 105 row = compat.layout_split(self.layout, factor=0.333333333, align=True) 106 row.prop(self, 'use_background_color', icon='WORLD') 107 row.prop(self, 'background_color', icon='COLOR', text="") 108 row.prop(self, 'is_round_background', icon=compat.icon('CLIPUV_DEHLT')) 109 110 self.layout.separator() 111 self.layout.prop_search(self, 'layer_image', context.blend_data, "images", icon='MOD_UVPROJECT') 112 113 def execute(self, context): 114 c = self.background_color[:] 115 context.scene['render_cm3d2_icon_background_color'] = ",".join([str(c[0]), str(c[1]), str(c[2])]) 116 context.scene['render_cm3d2_icon_background_color_layer_image'] = self.layer_image 117 118 override = context.copy() 119 obs = context.selected_objects 120 121 material_restores, pre_mate_settings = None, None 122 if self.mode == 'FACE_TEXTURE': 123 material_restores = [] 124 temp_mates = [] 125 for ob in obs: 126 material_restores.append(common.material_restore(ob)) 127 override['object'] = ob 128 bpy.ops.object.material_slot_add(override) 129 if len(ob.material_slots) > 0: 130 temp_mate = context.blend_data.materials.new("temp") 131 ob.material_slots[0].material = temp_mate 132 if compat.IS_LEGACY: 133 temp_mate.use_shadeless = True 134 temp_mate.use_face_texture = True 135 temp_mate.use_transparency = True 136 temp_mate.alpha = 0.0 137 temp_mate.use_face_texture_alpha = True 138 temp_mates.append(temp_mate) 139 140 elif self.mode == 'NOW_MATERIAL': 141 if compat.IS_LEGACY: 142 pre_mate_settings = [] 143 for ob in obs: 144 setting = [] 145 for slot in ob.material_slots: 146 if not slot.material: 147 continue 148 mate = slot.material 149 setting.append([mate, mate.use_shadeless]) 150 mate.use_shadeless = True 151 pre_mate_settings.append(setting) 152 153 xs, ys, zs = [], [], [] 154 if compat.IS_LEGACY: 155 for ob in obs: 156 if ob.type == 'MESH': 157 temp_me = ob.to_mesh(context.scene, apply_modifiers=True, settings='PREVIEW') 158 for vert in temp_me.vertices: 159 co = ob.matrix_world * vert.co 160 xs.append(co.x) 161 ys.append(co.y) 162 zs.append(co.z) 163 common.remove_data(temp_me) 164 else: 165 depsgraph = context.evaluated_depsgraph_get() 166 for ob in obs: 167 if ob.type == 'MESH': 168 # depsgraphから取得されたob_eval: すべてのmodifierを考慮 169 ob_eval = ob.evaluated_get(depsgraph) 170 temp_me = ob_eval.to_mesh() 171 for vert in temp_me.vertices: 172 co = ob.matrix_world @ vert.co 173 xs.append(co.x) 174 ys.append(co.y) 175 zs.append(co.z) 176 ob_eval.to_mesh_clear() 177 178 center_co = mathutils.Vector((0, 0, 0)) 179 center_co.x = (min(xs) + max(xs)) / 2.0 180 center_co.y = (min(ys) + max(ys)) / 2.0 181 center_co.z = (min(zs) + max(zs)) / 2.0 182 183 hide_render_restore = common.hide_render_restore() 184 pre_scene_camera = context.scene.camera 185 temp_camera = context.blend_data.cameras.new("render_cm3d2_icon_temp") 186 temp_camera_ob = context.blend_data.objects.new("render_cm3d2_icon_temp", temp_camera) 187 try: 188 maxs = [-999, -999, -999] 189 mins = [999, 999, 999] 190 for ob in obs: 191 for i in range(8): 192 for j in range(3): 193 v = ob.bound_box[i][j] 194 if maxs[j] < v: 195 maxs[j] = v 196 if v < mins[j]: 197 mins[j] = v 198 199 lens = [maxs[0] - mins[0]] 200 lens.append(maxs[1] - mins[1]) 201 lens.append(maxs[2] - mins[2]) 202 lens.sort() 203 zoom = lens[-1] * 1.2 204 205 compat.link(context.scene, temp_camera_ob) 206 context.scene.camera = temp_camera_ob 207 temp_camera.type = 'ORTHO' 208 temp_camera.ortho_scale = zoom * (self.zoom_multi * 0.01) 209 210 direct = self.camera_angle.copy() 211 direct.rotate( mathutils.Euler((math.radians(90), 0, 0), 'XYZ') ) 212 temp_camera_ob.rotation_mode = 'QUATERNION' 213 temp_camera_ob.rotation_quaternion = direct.to_track_quat('Z', 'Y') 214 temp_camera_ob.location = direct * 10 215 temp_camera_ob.location += center_co 216 vec = mathutils.Vector() 217 vec.x, vec.y = -self.camera_move.x, -self.camera_move.y 218 temp_camera_ob.location += compat.mul(direct.to_track_quat('Z', 'Y'), vec) 219 220 context.scene.render.resolution_x = self.resolution 221 context.scene.render.resolution_y = self.resolution 222 context.scene.render.resolution_percentage = 100 223 224 context.scene.world.light_settings.use_ambient_occlusion = False 225 if compat.IS_LEGACY: 226 context.scene.world.light_settings.ao_blend_type = 'ADD' 227 context.scene.world.light_settings.gather_method = 'RAYTRACE' 228 context.scene.world.light_settings.samples = 10 229 230 context.scene.render.alpha_mode = 'SKY' if self.use_background_color else 'TRANSPARENT' 231 context.scene.world.horizon_color = self.background_color 232 else: 233 # TODO 代替処理 234 pass 235 236 if self.use_freestyle: 237 pre_use_freestyle = context.scene.render.use_freestyle 238 pre_line_thickness = context.scene.render.line_thickness 239 context.scene.render.use_freestyle = True 240 context.scene.render.line_thickness = self.line_thickness 241 if compat.IS_LEGACY: 242 context.scene.render.layers.active.freestyle_settings.crease_angle = 1.58825 243 temp_lineset = context.scene.render.layers.active.freestyle_settings.linesets.new("temp") 244 temp_lineset.linestyle.color = self.line_color 245 else: 246 # TODO view_layersのactive取得方法 247 layer = context.scene.view_layers[0] 248 layer.freestyle_settings.crease_angle = 1.58825 249 temp_lineset = layer.freestyle_settings.linesets.new("temp") 250 temp_lineset.linestyle.color = self.line_color 251 252 # コンポジットノード # 253 pre_use_nodes = context.scene.use_nodes 254 context.scene.use_nodes = True 255 node_tree = context.scene.node_tree 256 node_tree.nodes.clear() 257 258 in_node = node_tree.nodes.new('CompositorNodeRLayers') 259 in_node.location = (0, 0) 260 261 img_node = node_tree.nodes.new('CompositorNodeImage') 262 img_node.location = (0, -300) 263 if "Icon Alpha" in context.blend_data.images: 264 icon_alpha_img = context.blend_data.images["Icon Alpha"] 265 else: 266 blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend") 267 with context.blend_data.libraries.load(blend_path) as (data_from, data_to): 268 data_to.images = ["Icon Alpha"] 269 icon_alpha_img = data_to.images[0] 270 img_node.image = icon_alpha_img 271 272 scale_node = node_tree.nodes.new('CompositorNodeScale') 273 scale_node.location = (250, -300) 274 scale_node.space = 'RENDER_SIZE' 275 276 mix_node = node_tree.nodes.new('CompositorNodeMixRGB') 277 mix_node.location = (500, -100) 278 mix_node.blend_type = 'MULTIPLY' 279 280 alpha_node = node_tree.nodes.new('CompositorNodeSetAlpha') 281 alpha_node.location = (750, 0) 282 283 out_node = node_tree.nodes.new('CompositorNodeComposite') 284 out_node.location = (1500, 0) 285 286 layer_img = None 287 if self.layer_image in context.blend_data.images: 288 layer_img = context.blend_data.images[self.layer_image] 289 if layer_img: 290 layer_img_node = node_tree.nodes.new('CompositorNodeImage') 291 layer_img_node.location = (750, -200) 292 layer_img_node.image = layer_img 293 294 layer_scale_node = node_tree.nodes.new('CompositorNodeScale') 295 layer_scale_node.location = (1000, -200) 296 layer_scale_node.space = 'RENDER_SIZE' 297 298 layer_add_node = node_tree.nodes.new('CompositorNodeAlphaOver') 299 layer_add_node.location = (1250, 0) 300 301 node_tree.links.new(layer_add_node.inputs[1], alpha_node.outputs[0]) 302 node_tree.links.new(layer_scale_node.inputs[0], layer_img_node.outputs[0]) 303 node_tree.links.new(layer_add_node.inputs[2], layer_scale_node.outputs[0]) 304 node_tree.links.new(out_node.inputs[0], layer_add_node.outputs[0]) 305 else: 306 node_tree.links.new(out_node.inputs[0], alpha_node.outputs[0]) 307 308 node_tree.links.new(alpha_node.inputs[0], in_node.outputs[0]) 309 node_tree.links.new(mix_node.inputs[1], in_node.outputs[1]) 310 node_tree.links.new(scale_node.inputs[0], img_node.outputs[0]) 311 node_tree.links.new(mix_node.inputs[2], scale_node.outputs[0]) 312 if self.is_round_background: 313 node_tree.links.new(alpha_node.inputs[1], mix_node.outputs[0]) 314 # コンポジットノード # 315 316 bpy.ops.render.render() 317 318 node_tree.nodes.clear() 319 context.scene.use_nodes = False 320 common.remove_data([icon_alpha_img]) 321 322 if self.use_freestyle: 323 context.scene.render.use_freestyle = pre_use_freestyle 324 context.scene.render.line_thickness = pre_line_thickness 325 common.remove_data([temp_lineset.linestyle]) 326 if compat.IS_LEGACY: 327 context.scene.render.layers.active.freestyle_settings.linesets.remove(temp_lineset) 328 else: 329 layer = context.scene.view_layers[0] 330 layer.freestyle_settings.linesets.remove(temp_lineset) 331 332 img = context.blend_data.images["Render Result"] 333 tex_basename = common.remove_serial_number(context.active_object.name.split('.')[0]) 334 img['tex Name'] = tex_basename + "_i_.tex" 335 img['cm3d2_path'] = common.BASE_PATH_TEX + tex_basename + "_i_.png" 336 area = common.get_request_area(context, 'IMAGE_EDITOR') 337 common.set_area_space_attr(area, 'image', img) 338 339 finally: 340 common.remove_data([temp_camera_ob, temp_camera]) 341 context.scene.camera = pre_scene_camera 342 343 hide_render_restore.restore() 344 if material_restores: 345 for material_restore in material_restores: 346 material_restore.restore() 347 common.remove_data(temp_mates) 348 if pre_mate_settings: 349 for ob_mate in pre_mate_settings: 350 for mate, is_shadeless in ob_mate: 351 mate.use_shadeless = is_shadeless 352 353 return {'FINISHED'}
items =
[('FACE_TEXTURE', '面のテクスチャで', '', 'FACESEL_HLT', 1), ('NOW_MATERIAL', '今のマテリアルで', '', 'MATERIAL', 2)]
mode: <_PropertyDeferred, <built-in function EnumProperty>, {'items': [('FACE_TEXTURE', '面のテクスチャで', '', 'FACESEL_HLT', 1), ('NOW_MATERIAL', '今のマテリアルで', '', 'MATERIAL', 2)], 'name': 'モード', 'default': 'FACE_TEXTURE', 'attr': 'mode'}> =
<_PropertyDeferred, <built-in function EnumProperty>, {'items': [('FACE_TEXTURE', '面のテクスチャで', '', 'FACESEL_HLT', 1), ('NOW_MATERIAL', '今のマテリアルで', '', 'MATERIAL', 2)], 'name': 'モード', 'default': 'FACE_TEXTURE', 'attr': 'mode'}>
use_freestyle: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '輪郭線を描画', 'default': True, 'attr': 'use_freestyle'}> =
<_PropertyDeferred, <built-in function BoolProperty>, {'name': '輪郭線を描画', 'default': True, 'attr': 'use_freestyle'}>
line_thickness: <_PropertyDeferred, <built-in function FloatProperty>, {'name': '線の太さ', 'default': 0.2, 'min': 0, 'max': 0.5, 'soft_min': 0, 'soft_max': 0.5, 'step': 10, 'precision': 2, 'subtype': 'PIXEL', 'attr': 'line_thickness'}> =
<_PropertyDeferred, <built-in function FloatProperty>, {'name': '線の太さ', 'default': 0.2, 'min': 0, 'max': 0.5, 'soft_min': 0, 'soft_max': 0.5, 'step': 10, 'precision': 2, 'subtype': 'PIXEL', 'attr': 'line_thickness'}>
line_color: <_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': '線の色', 'default': (0, 0, 0), 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'subtype': 'COLOR', 'size': 3, 'attr': 'line_color'}> =
<_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': '線の色', 'default': (0, 0, 0), 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'subtype': 'COLOR', 'size': 3, 'attr': 'line_color'}>
resolution: <_PropertyDeferred, <built-in function IntProperty>, {'name': '解像度', 'default': 80, 'min': 10, 'max': 800, 'soft_min': 10, 'soft_max': 800, 'subtype': 'PIXEL', 'attr': 'resolution'}> =
<_PropertyDeferred, <built-in function IntProperty>, {'name': '解像度', 'default': 80, 'min': 10, 'max': 800, 'soft_min': 10, 'soft_max': 800, 'subtype': 'PIXEL', 'attr': 'resolution'}>
camera_angle: <_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': 'カメラ角度', 'default': (0.576667, 0.576667, 0.578715), 'min': -10, 'max': 10, 'soft_min': -10, 'soft_max': 10, 'step': 1, 'precision': 2, 'subtype': 'DIRECTION', 'size': 3, 'attr': 'camera_angle'}> =
<_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': 'カメラ角度', 'default': (0.576667, 0.576667, 0.578715), 'min': -10, 'max': 10, 'soft_min': -10, 'soft_max': 10, 'step': 1, 'precision': 2, 'subtype': 'DIRECTION', 'size': 3, 'attr': 'camera_angle'}>
camera_move: <_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': 'カメラ移動', 'default': (0, 0), 'min': -10, 'max': 10, 'soft_min': -10, 'soft_max': 10, 'step': 10, 'precision': 2, 'subtype': 'XYZ', 'size': 2, 'attr': 'camera_move'}> =
<_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': 'カメラ移動', 'default': (0, 0), 'min': -10, 'max': 10, 'soft_min': -10, 'soft_max': 10, 'step': 10, 'precision': 2, 'subtype': 'XYZ', 'size': 2, 'attr': 'camera_move'}>
zoom_multi: <_PropertyDeferred, <built-in function IntProperty>, {'name': 'ズーム倍率', 'default': 100, 'min': 10, 'max': 190, 'soft_min': 10, 'soft_max': 190, 'step': 10, 'subtype': 'PERCENTAGE', 'attr': 'zoom_multi'}> =
<_PropertyDeferred, <built-in function IntProperty>, {'name': 'ズーム倍率', 'default': 100, 'min': 10, 'max': 190, 'soft_min': 10, 'soft_max': 190, 'step': 10, 'subtype': 'PERCENTAGE', 'attr': 'zoom_multi'}>
use_background_color: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '背景を使用', 'default': True, 'attr': 'use_background_color'}> =
<_PropertyDeferred, <built-in function BoolProperty>, {'name': '背景を使用', 'default': True, 'attr': 'use_background_color'}>
background_color: <_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': '背景色', 'default': (1, 1, 1), 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'subtype': 'COLOR', 'size': 3, 'attr': 'background_color'}> =
<_PropertyDeferred, <built-in function FloatVectorProperty>, {'name': '背景色', 'default': (1, 1, 1), 'min': 0, 'max': 1, 'soft_min': 0, 'soft_max': 1, 'step': 10, 'precision': 2, 'subtype': 'COLOR', 'size': 3, 'attr': 'background_color'}>
is_round_background: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '隅を丸める', 'default': True, 'attr': 'is_round_background'}> =
<_PropertyDeferred, <built-in function BoolProperty>, {'name': '隅を丸める', 'default': True, 'attr': 'is_round_background'}>
layer_image: <_PropertyDeferred, <built-in function StringProperty>, {'name': '重ねる画像', 'default': '', 'attr': 'layer_image'}> =
<_PropertyDeferred, <built-in function StringProperty>, {'name': '重ねる画像', 'default': '', 'attr': 'layer_image'}>
def
invoke(self, context, event):
57 def invoke(self, context, event): 58 obs = context.selected_objects 59 for ob in obs: 60 if ob.type != 'MESH': 61 continue 62 me = ob.data 63 uv = compat.get_active_uv(me) 64 if uv and uv.data[0]: 65 self.mode = 'FACE_TEXTURE' 66 break 67 else: 68 self.mode = 'NOW_MATERIAL' 69 70 if 'render_cm3d2_icon_background_color' in context.scene: 71 try: 72 color = str(context.scene['render_cm3d2_icon_background_color']).split(",") 73 if len(color) == 3: 74 self.background_color[0] = float(color[0]) 75 self.background_color[1] = float(color[1]) 76 self.background_color[2] = float(color[2]) 77 except: 78 pass 79 if 'render_cm3d2_icon_background_color_layer_image' in context.scene: 80 self.layer_image = context.scene['render_cm3d2_icon_background_color_layer_image'] 81 82 return context.window_manager.invoke_props_dialog(self)
def
draw(self, context):
84 def draw(self, context): 85 self.layout.prop(self, 'resolution', icon=compat.icon('FILE_IMAGE'), slider=True) 86 col = self.layout.column(align=True) 87 col.label(text="テクスチャ参照方法", icon=compat.icon('SHADING_TEXTURE')) 88 row = col.row() 89 row.prop(self, 'mode', icon=compat.icon('SHADING_TEXTURE'), expand=True) 90 self.layout.separator() 91 92 row = compat.layout_split(self.layout, factor=1 / 3, align=True) 93 row.prop(self, 'use_freestyle', icon='LINE_DATA', text="輪郭線") 94 row.prop(self, 'line_thickness', icon='ARROW_LEFTRIGHT', slider=True, text="") 95 row.prop(self, 'line_color', icon='COLOR', text="") 96 self.layout.separator() 97 98 col = self.layout.column(align=True) 99 col.label(text="カメラ角度", icon='FILE_REFRESH') 100 col.prop(self, 'camera_angle', text="") 101 self.layout.prop(self, 'camera_move', icon='ARROW_LEFTRIGHT') 102 self.layout.prop(self, 'zoom_multi', icon='VIEWZOOM', slider=True) 103 self.layout.separator() 104 105 row = compat.layout_split(self.layout, factor=0.333333333, align=True) 106 row.prop(self, 'use_background_color', icon='WORLD') 107 row.prop(self, 'background_color', icon='COLOR', text="") 108 row.prop(self, 'is_round_background', icon=compat.icon('CLIPUV_DEHLT')) 109 110 self.layout.separator() 111 self.layout.prop_search(self, 'layer_image', context.blend_data, "images", icon='MOD_UVPROJECT')
def
execute(self, context):
113 def execute(self, context): 114 c = self.background_color[:] 115 context.scene['render_cm3d2_icon_background_color'] = ",".join([str(c[0]), str(c[1]), str(c[2])]) 116 context.scene['render_cm3d2_icon_background_color_layer_image'] = self.layer_image 117 118 override = context.copy() 119 obs = context.selected_objects 120 121 material_restores, pre_mate_settings = None, None 122 if self.mode == 'FACE_TEXTURE': 123 material_restores = [] 124 temp_mates = [] 125 for ob in obs: 126 material_restores.append(common.material_restore(ob)) 127 override['object'] = ob 128 bpy.ops.object.material_slot_add(override) 129 if len(ob.material_slots) > 0: 130 temp_mate = context.blend_data.materials.new("temp") 131 ob.material_slots[0].material = temp_mate 132 if compat.IS_LEGACY: 133 temp_mate.use_shadeless = True 134 temp_mate.use_face_texture = True 135 temp_mate.use_transparency = True 136 temp_mate.alpha = 0.0 137 temp_mate.use_face_texture_alpha = True 138 temp_mates.append(temp_mate) 139 140 elif self.mode == 'NOW_MATERIAL': 141 if compat.IS_LEGACY: 142 pre_mate_settings = [] 143 for ob in obs: 144 setting = [] 145 for slot in ob.material_slots: 146 if not slot.material: 147 continue 148 mate = slot.material 149 setting.append([mate, mate.use_shadeless]) 150 mate.use_shadeless = True 151 pre_mate_settings.append(setting) 152 153 xs, ys, zs = [], [], [] 154 if compat.IS_LEGACY: 155 for ob in obs: 156 if ob.type == 'MESH': 157 temp_me = ob.to_mesh(context.scene, apply_modifiers=True, settings='PREVIEW') 158 for vert in temp_me.vertices: 159 co = ob.matrix_world * vert.co 160 xs.append(co.x) 161 ys.append(co.y) 162 zs.append(co.z) 163 common.remove_data(temp_me) 164 else: 165 depsgraph = context.evaluated_depsgraph_get() 166 for ob in obs: 167 if ob.type == 'MESH': 168 # depsgraphから取得されたob_eval: すべてのmodifierを考慮 169 ob_eval = ob.evaluated_get(depsgraph) 170 temp_me = ob_eval.to_mesh() 171 for vert in temp_me.vertices: 172 co = ob.matrix_world @ vert.co 173 xs.append(co.x) 174 ys.append(co.y) 175 zs.append(co.z) 176 ob_eval.to_mesh_clear() 177 178 center_co = mathutils.Vector((0, 0, 0)) 179 center_co.x = (min(xs) + max(xs)) / 2.0 180 center_co.y = (min(ys) + max(ys)) / 2.0 181 center_co.z = (min(zs) + max(zs)) / 2.0 182 183 hide_render_restore = common.hide_render_restore() 184 pre_scene_camera = context.scene.camera 185 temp_camera = context.blend_data.cameras.new("render_cm3d2_icon_temp") 186 temp_camera_ob = context.blend_data.objects.new("render_cm3d2_icon_temp", temp_camera) 187 try: 188 maxs = [-999, -999, -999] 189 mins = [999, 999, 999] 190 for ob in obs: 191 for i in range(8): 192 for j in range(3): 193 v = ob.bound_box[i][j] 194 if maxs[j] < v: 195 maxs[j] = v 196 if v < mins[j]: 197 mins[j] = v 198 199 lens = [maxs[0] - mins[0]] 200 lens.append(maxs[1] - mins[1]) 201 lens.append(maxs[2] - mins[2]) 202 lens.sort() 203 zoom = lens[-1] * 1.2 204 205 compat.link(context.scene, temp_camera_ob) 206 context.scene.camera = temp_camera_ob 207 temp_camera.type = 'ORTHO' 208 temp_camera.ortho_scale = zoom * (self.zoom_multi * 0.01) 209 210 direct = self.camera_angle.copy() 211 direct.rotate( mathutils.Euler((math.radians(90), 0, 0), 'XYZ') ) 212 temp_camera_ob.rotation_mode = 'QUATERNION' 213 temp_camera_ob.rotation_quaternion = direct.to_track_quat('Z', 'Y') 214 temp_camera_ob.location = direct * 10 215 temp_camera_ob.location += center_co 216 vec = mathutils.Vector() 217 vec.x, vec.y = -self.camera_move.x, -self.camera_move.y 218 temp_camera_ob.location += compat.mul(direct.to_track_quat('Z', 'Y'), vec) 219 220 context.scene.render.resolution_x = self.resolution 221 context.scene.render.resolution_y = self.resolution 222 context.scene.render.resolution_percentage = 100 223 224 context.scene.world.light_settings.use_ambient_occlusion = False 225 if compat.IS_LEGACY: 226 context.scene.world.light_settings.ao_blend_type = 'ADD' 227 context.scene.world.light_settings.gather_method = 'RAYTRACE' 228 context.scene.world.light_settings.samples = 10 229 230 context.scene.render.alpha_mode = 'SKY' if self.use_background_color else 'TRANSPARENT' 231 context.scene.world.horizon_color = self.background_color 232 else: 233 # TODO 代替処理 234 pass 235 236 if self.use_freestyle: 237 pre_use_freestyle = context.scene.render.use_freestyle 238 pre_line_thickness = context.scene.render.line_thickness 239 context.scene.render.use_freestyle = True 240 context.scene.render.line_thickness = self.line_thickness 241 if compat.IS_LEGACY: 242 context.scene.render.layers.active.freestyle_settings.crease_angle = 1.58825 243 temp_lineset = context.scene.render.layers.active.freestyle_settings.linesets.new("temp") 244 temp_lineset.linestyle.color = self.line_color 245 else: 246 # TODO view_layersのactive取得方法 247 layer = context.scene.view_layers[0] 248 layer.freestyle_settings.crease_angle = 1.58825 249 temp_lineset = layer.freestyle_settings.linesets.new("temp") 250 temp_lineset.linestyle.color = self.line_color 251 252 # コンポジットノード # 253 pre_use_nodes = context.scene.use_nodes 254 context.scene.use_nodes = True 255 node_tree = context.scene.node_tree 256 node_tree.nodes.clear() 257 258 in_node = node_tree.nodes.new('CompositorNodeRLayers') 259 in_node.location = (0, 0) 260 261 img_node = node_tree.nodes.new('CompositorNodeImage') 262 img_node.location = (0, -300) 263 if "Icon Alpha" in context.blend_data.images: 264 icon_alpha_img = context.blend_data.images["Icon Alpha"] 265 else: 266 blend_path = os.path.join(os.path.dirname(__file__), "append_data.blend") 267 with context.blend_data.libraries.load(blend_path) as (data_from, data_to): 268 data_to.images = ["Icon Alpha"] 269 icon_alpha_img = data_to.images[0] 270 img_node.image = icon_alpha_img 271 272 scale_node = node_tree.nodes.new('CompositorNodeScale') 273 scale_node.location = (250, -300) 274 scale_node.space = 'RENDER_SIZE' 275 276 mix_node = node_tree.nodes.new('CompositorNodeMixRGB') 277 mix_node.location = (500, -100) 278 mix_node.blend_type = 'MULTIPLY' 279 280 alpha_node = node_tree.nodes.new('CompositorNodeSetAlpha') 281 alpha_node.location = (750, 0) 282 283 out_node = node_tree.nodes.new('CompositorNodeComposite') 284 out_node.location = (1500, 0) 285 286 layer_img = None 287 if self.layer_image in context.blend_data.images: 288 layer_img = context.blend_data.images[self.layer_image] 289 if layer_img: 290 layer_img_node = node_tree.nodes.new('CompositorNodeImage') 291 layer_img_node.location = (750, -200) 292 layer_img_node.image = layer_img 293 294 layer_scale_node = node_tree.nodes.new('CompositorNodeScale') 295 layer_scale_node.location = (1000, -200) 296 layer_scale_node.space = 'RENDER_SIZE' 297 298 layer_add_node = node_tree.nodes.new('CompositorNodeAlphaOver') 299 layer_add_node.location = (1250, 0) 300 301 node_tree.links.new(layer_add_node.inputs[1], alpha_node.outputs[0]) 302 node_tree.links.new(layer_scale_node.inputs[0], layer_img_node.outputs[0]) 303 node_tree.links.new(layer_add_node.inputs[2], layer_scale_node.outputs[0]) 304 node_tree.links.new(out_node.inputs[0], layer_add_node.outputs[0]) 305 else: 306 node_tree.links.new(out_node.inputs[0], alpha_node.outputs[0]) 307 308 node_tree.links.new(alpha_node.inputs[0], in_node.outputs[0]) 309 node_tree.links.new(mix_node.inputs[1], in_node.outputs[1]) 310 node_tree.links.new(scale_node.inputs[0], img_node.outputs[0]) 311 node_tree.links.new(mix_node.inputs[2], scale_node.outputs[0]) 312 if self.is_round_background: 313 node_tree.links.new(alpha_node.inputs[1], mix_node.outputs[0]) 314 # コンポジットノード # 315 316 bpy.ops.render.render() 317 318 node_tree.nodes.clear() 319 context.scene.use_nodes = False 320 common.remove_data([icon_alpha_img]) 321 322 if self.use_freestyle: 323 context.scene.render.use_freestyle = pre_use_freestyle 324 context.scene.render.line_thickness = pre_line_thickness 325 common.remove_data([temp_lineset.linestyle]) 326 if compat.IS_LEGACY: 327 context.scene.render.layers.active.freestyle_settings.linesets.remove(temp_lineset) 328 else: 329 layer = context.scene.view_layers[0] 330 layer.freestyle_settings.linesets.remove(temp_lineset) 331 332 img = context.blend_data.images["Render Result"] 333 tex_basename = common.remove_serial_number(context.active_object.name.split('.')[0]) 334 img['tex Name'] = tex_basename + "_i_.tex" 335 img['cm3d2_path'] = common.BASE_PATH_TEX + tex_basename + "_i_.png" 336 area = common.get_request_area(context, 'IMAGE_EDITOR') 337 common.set_area_space_attr(area, 'image', img) 338 339 finally: 340 common.remove_data([temp_camera_ob, temp_camera]) 341 context.scene.camera = pre_scene_camera 342 343 hide_render_restore.restore() 344 if material_restores: 345 for material_restore in material_restores: 346 material_restore.restore() 347 common.remove_data(temp_mates) 348 if pre_mate_settings: 349 for ob_mate in pre_mate_settings: 350 for mate, is_shadeless in ob_mate: 351 mate.use_shadeless = is_shadeless 352 353 return {'FINISHED'}
Inherited Members
- bpy_types.Operator
- as_keywords
- poll_message_set
- builtins.bpy_struct
- keys
- values
- get
- pop
- as_pointer
- keyframe_insert
- keyframe_delete
- driver_add
- driver_remove
- is_property_set
- property_unset
- is_property_readonly
- is_property_overridable_library
- property_overridable_library_set
- path_resolve
- path_from_id
- type_recast
- bl_rna_get_subclass_py
- bl_rna_get_subclass
- id_properties_ensure
- id_properties_clear
- id_properties_ui
- id_data